package com.qisu.command;

import com.qisu.converters.FieldConverter;

/**
 *
 * @author alsan
 *
 * @param <T>
 */
// @formatter:off
public class CommandFieldDef<T> {
	private int _position;
	public int getPosition() { return _position; }
	public void setPosition(int position) { _position = position; }

	private int _length;
	public int getLength() { return _length; }

	private String _description;
	public String getDescription() { return _description; }

	private FieldConverter<T> _converter;
	public boolean hasConverter() { return null != _converter; }

	private T _value;
	public T getValue() { return _value; }

	public CommandFieldDef(int length) { _length = length; }
	public CommandFieldDef(int length, FieldConverter<T> converter) {
		this(length);
		_converter = converter;
	}

	public CommandFieldDef(int length, FieldConverter<T> converter, String description) {
		this(length, converter);
		_description = description;
	}

	public void convert(byte[] data) {
		_value = _converter.converter(data, _position, _length);
	}
}
